//
//  LXM_DataDownloadTools.m
//  UILesson17_imageDownloader
//
//  Created by 刘晓萌 on 15/10/29.
//  Copyright © 2015年 刘晓萌. All rights reserved.
//

#import "LXM_DataDownloadTools.h"

@implementation LXM_DataDownloadTools
+(void)downloadDataWithURL:(NSString *)urlString andMethod:(urlMethod )method andBody:(NSString *)body andBlock:(OptionBlock)block{
    NSURL *url = [NSURL URLWithString:urlString];
    NSMutableURLRequest *request =[NSMutableURLRequest requestWithURL:url];
    if (method == POST) {
        [request setHTTPMethod:@"POST"];
        [request setHTTPBody:[body dataUsingEncoding:NSUTF8StringEncoding]];
    }
    [NSURLConnection sendAsynchronousRequest:request queue:[NSOperationQueue mainQueue] completionHandler:^(NSURLResponse * _Nullable response, NSData * _Nullable data, NSError * _Nullable connectionError) {
        block(data);
    }];
}
@end
